import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:ls_work/a_elder/models/elder_entity.dart';
import 'package:ls_work/res/gaps.dart';
import 'package:ls_work/res/resources.dart';
import 'package:ls_work/viewmodel/leave/add_leave_view_model.dart';
import 'package:ls_work/widgets/bottom_input_widget.dart';
import 'package:ls_work/widgets/requir_text_view.dart';

import '../../widgets/title_value_widget.dart';

class AddLeavePage extends BaseStatefulMvvmWidget {
  final ElderInfo? info;

  AddLeavePage({this.info});

  @override
  State<StatefulWidget> createState() => _AddLeaveState();
}

class _AddLeaveState extends BaseMvvmState<AddLeaveViewModel, AddLeavePage> {
  @override
  Widget buildLoadingContentView() {
    return Column(
      children: [
        ListView(
          children: [
            TitleValueWidget(
              "长者姓名",
              hint: "请选择",
              text: viewModel.older?.name ?? "",
              isRequired: true,
              rightWeight: Icon(Icons.qr_code_scanner).onTap(() {
                viewModel.scanOld();
              }),
            ).onTap(() {
              if(widget.info==null){
                viewModel.selectOlder();
              }
            }),
            Gaps.line,
            TitleValueWidget(
              "外出时间",
              hint: "请选择",
              text: viewModel.leaveTime,
              isRequired: true,
            ).onTap(() {
              viewModel.selectLeaveTime();
            }),
            Gaps.line,
            TitleValueWidget(
              "外出事由",
              hint: "请选择",
              isRequired: true,
              text: viewModel.leaveReasonName,
            ).onTap(() {
              viewModel.selectReason();
            }),
            Gaps.line,

            TitleValueWidget(
              "陪同人",
              hint: "请选择",
              text: viewModel.accompanyName,
            ).onTap(() {
              // showBottomInput(context,content: viewModel.accompanyName,keyboard: CommonInputType.phone,onSubmit: (str){
              //   setState(() {
              //     viewModel.accompanyName = str;
              //   });
              // });
              viewModel.selectFamily();
            }),
            Gaps.line,
            TitleValueWidget(
              "陪同人电话",
              hint: "请输入",
              text: viewModel.accompanyMobile,
            ).onTap(() {
              showBottomInput(context,content: viewModel.accompanyMobile,keyboard: CommonInputType.phone,onSubmit: (str){
                setState(() {
                  viewModel.accompanyMobile = str;
                });
              });
            }),
            Gaps.line,
            TitleValueWidget(
              "与长者关系",
              hint: "请选择",
              text: viewModel.relationshipName,
            ).onTap(() {
              viewModel.selectRelation();
            }),

            // IconTitleWidget(
            //   '陪同人电话',
            //   showArrow: false,
            //   contentWidget: CommonInput(
            //     hintText: '请输入',
            //     isDense: true,
            //     padding: EdgeInsets.zero,
            //     border: InputBorder.none,
            //     textAlign: TextAlign.end,
            //     keyboardType: CommonInputType.phone,
            //     maxLines: 2,
            //     onChanged: (str) {
            //       viewModel.accompanyMobile = str;
            //     },
            //   )
            //       .addToContainer(
            //           color: Colors.white, alignment: Alignment.center)
            //       .setWeight(2),
            // ),
            Gaps.midLine,
            TitleValueWidget(
              "预计销假时间",
              hint: "请选择",
              text: viewModel.planBackTime,
            ).onTap(() {
              viewModel.selectPlanBackTime();
            }),
            Gaps.line,
            // TitleValueWidget(
            //   "实际销假时间",
            //   hint: "请选择",
            //   text: viewModel.backTime,
            // ).onTap(() {
            //   viewModel.selectBackTime();
            // }),
            // Gaps.midLine,
            CommonText("备注").addToContainer(
                margin: EdgeInsets.symmetric(horizontal: 16, vertical: 16)),

            CommonInput(
              hintText: '输入备注信息',
              border: InputBorder.none,
              padding: EdgeInsets.zero,
              maxLines: 6,
              onChanged: (str) {
                viewModel.leaveRemark = str;
              },
              keyboardType: CommonInputType.multiline,
            ).addToContainer(
                padding: EdgeInsets.all(10),
                decoration: BoxDecoration(
                    color: Color(0xffebedf0),
                    borderRadius: BorderRadius.circular(8)),
                margin: EdgeInsets.symmetric(horizontal: 16)),
            RequireTextView("是否同步确认离院").addToContainer(
                margin: EdgeInsets.symmetric(horizontal: 16, vertical: 16)),
            Column(
              children: viewModel.syncData.map((e) {
                return RadioListTile<String>(value: e.id!, groupValue: viewModel.selectSync, onChanged: (value){
                  setState(() {
                    viewModel.selectSync = value!;
                  });
                },title: CommonText(e.name),);
              }).toList(),
            )

          ],
        ).setWeight(1),
        ElevatedButton(
          onPressed: () {
            viewModel.addLeave();
          },
          child: CommonText('提交', textSize: 17, textColor: Colors.white),
          style: ButtonStyles.submit_btn_style,
        ).addToContainer(
            margin: EdgeInsets.only(left: 16, right: 16, bottom: 16))
      ],
    );
  }

  @override
  Widget buildRootView(BuildContext context, Widget loadingContentWidget) {
    return Scaffold(
      appBar: AppBar(
        title: Text("新增出入院信息"),
      ),
      body: loadingContentWidget,
    );
  }

  @override
  AddLeaveViewModel createViewModel() {
    return AddLeaveViewModel(context,info: widget.info);
  }

  @override
  void onRetryClick() {
    // TODO: implement onRetryClick
  }
}
